/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kkks.spring_rest.tick.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日志帮助类
 * @author Davelin
 */
public class LogHelper {

    private static String getTitle(LogType type) {
        String result = "";
        if (type == LogType.Info) {
            result = "Info:";
        } else if (type == LogType.Debug) {
            result = "Debug:";
        } else if (type == LogType.Exception) {
            result = "Exception:";
        } else if (type == LogType.Waring) {
            result = "Waring:";
        } else if (type == LogType.Critical) {
            result = "Critical:";
        } else if (type == LogType.Input) {
            result = "WebService Input:";
        } else if (type == LogType.Output) {
            result = "WebService Output:";
        }

        return result;
    }
    static SimpleDateFormat sdf = new SimpleDateFormat("时间：yyyy年MM月dd日_HH时mm分ss秒 ");

    public static void log(LogType type, String content) {
        String time = sdf.format(new Date());
        System.out.println(getTitle(type) + time + content);
    }

    public static void logInfo(String content) {
        log(LogType.Info, content);
    }

    public static void logDebug(String content) {
        log(LogType.Debug, content);
    }

    public static void logException(String content) {
        log(LogType.Exception, content);
    }

    public static void logCritical(String content) {
        log(LogType.Critical, content);
    }

    public static void logWaring(String content) {
        log(LogType.Waring, content);
    }

    /**
     * 记录webservice输入值
     * @param content 
     */
    public static void logInput(String content) {
        log(LogType.Input, content);
    }

    /**
     * 记录webservice返回值
     * @param content 
     */
    public static void logOutput(String content) {
        log(LogType.Output, content);
    }

    public static void logOutput(String method, Boolean result) {
        if (result != null) {
            log(LogType.Output, method + ":" + result);
        } else {
            log(LogType.Output, method + ":UserTokenInvalid.");
        }
    }
}
